///// Patterns /////
    using System;
    using System.Collections.Generic;
    using System.Collections;
    //using System.Linq;
    using System.Text;
    using System.IO;
    using iTextSharp.text;
    using iTextSharp.text.pdf;


namespace Patterns
{
    class Program
    {
        static void Main(string[] args)
        {
            // Generates a PDF file demonstrating the use of patterns.
            // 
            // @param args:  no arguments needed here

            Console.WriteLine("Chapter 11: example Patterns");
            Console.WriteLine("-> Creates a PDF file demonstrating tiling patterns.");
            Console.WriteLine("-> extra resource needed: iTextLogo.gif (chapter 10)");
            Console.WriteLine("-> file generated: patterns.pdf");
            // step 1: creation of a document-object
            Document document = new Document();
            try
            {
                // step 2:
                // we create a writer
                PdfWriter writer = PdfWriter.GetInstance(
                    // that listens to the document
                        document,
                    // and directs a PDF-stream to a file
                        new FileStream("patterns.pdf", FileMode.Create));
                // step 3: we open the document
                document.Open();
                // step 4:
                PdfContentByte cb = writer.DirectContent;

                PdfPatternPainter square = cb.CreatePattern(15, 15);
                square.SetColorFill(BaseColor.MAGENTA);
                square.SetColorStroke(BaseColor.RED);
                square.Rectangle(5, 5, 5, 5);
                square.FillStroke();
                PdfPatternPainter ellipse = cb.CreatePattern(15, 10, 20, 25);
                ellipse.SetColorFill(BaseColor.ORANGE);
                ellipse.SetColorStroke(BaseColor.RED);
                ellipse.Ellipse(2f, 2f, 13f, 8f);
                ellipse.FillStroke();
                PdfPatternPainter circle = cb.CreatePattern(15, 15, 10, 20, BaseColor.BLUE);
                circle.Circle(7.5f, 7.5f, 2.5f);
                circle.Fill();
                PdfPatternPainter line = cb.CreatePattern(5, 10, null);
                line.SetLineWidth(1);
                line.MoveTo(3, -1);
                line.LineTo(3, 11);
                line.Stroke();
                Image img = Image.GetInstance(@"D:\Temp\DD.jpg");
                PdfPatternPainter img_pattern = cb.CreatePattern(img.ScaledWidth, img.ScaledHeight, img.ScaledWidth, img.ScaledHeight);
                img_pattern.AddImage(img, img.ScaledWidth, 0f, 0f, img.ScaledHeight, 0f, 0f);
                img_pattern.SetPatternMatrix(1f, 0f, 0f, 1f, 60f, 60f);

                PatternColor squares = new PatternColor(square);
                PatternColor ellipses = new PatternColor(ellipse);
                PatternColor circles = new PatternColor(circle);
                PatternColor lines = new PatternColor(line);

                cb.SetColorFill(squares);
                cb.Rectangle(36, 716, 72, 72);
                cb.FillStroke();
                cb.SetColorFill(ellipses);
                cb.Rectangle(144, 716, 72, 72);
                cb.FillStroke();
                cb.SetColorFill(circles);
                cb.Rectangle(252, 716, 72, 72);
                cb.FillStroke();
                cb.SetColorFill(lines);
                cb.Rectangle(360, 716, 72, 72);
                cb.FillStroke();
                cb.SetPatternFill(circle, BaseColor.RED);
                cb.Rectangle(470, 716, 72, 72);
                cb.FillStroke();

                cb.SetPatternFill(line, BaseColor.RED);
                cb.Rectangle(36, 608, 72, 72);
                cb.FillStroke();
                cb.SetPatternFill(line, BaseColor.GREEN);
                cb.Rectangle(144, 608, 72, 72);
                cb.FillStroke();
                cb.SetPatternFill(line, BaseColor.BLUE);
                cb.Rectangle(252, 608, 72, 72);
                cb.FillStroke();
                cb.SetPatternFill(line, BaseColor.YELLOW);
                cb.Rectangle(360, 608, 72, 72);
                cb.FillStroke();
                cb.SetPatternFill(line, BaseColor.BLACK);
                cb.Rectangle(470, 608, 72, 72);
                cb.FillStroke();

                cb.SetPatternFill(img_pattern);
                cb.Ellipse(36, 520, 360, 590);
                cb.FillStroke();
            }

            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }

            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            // step 5: we close the document
            document.Close();

            Console.ReadLine();
        }
    }
}

///// This page is still under construction /////